package net.wanho.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.entity.User;
import net.wanho.service.UserService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2023-08-18 11:07
 * Description：<描述>
 */
@Api(tags = "01.用户模块")
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @ApiOperation("添加用户")
    @PostMapping
    public AjaxResult add(@ApiParam("用户信息") @RequestBody User user) {
        userService.add(user);
        return AjaxResult.success(user);
    }

    @ApiOperation("修改用户")
    @PutMapping
    public AjaxResult modify(@ApiParam("用户信息") User user) {
        userService.modify(user);
        return AjaxResult.success(user);
    }

    @ApiOperation("根据id删除用户")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@ApiParam("用户id") @PathVariable Integer id) {
        userService.removeById(id);
        return AjaxResult.success();
    }

    @ApiOperation("查询所有用户")
    // @ApiIgnore
    @GetMapping
    public AjaxResult findAll() {
        return AjaxResult.success(userService.findAll());
    }

    @ApiOperation("根据id查询用户")
    @GetMapping("/{id}")
    public AjaxResult findById(@ApiParam("用户id") @PathVariable Integer id){
        return AjaxResult.success(userService.findById(id));
    }

    @ApiOperation("分页查询用户")
    @GetMapping("/page")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum, @ApiParam("页大小") Integer pageSize){
        return AjaxResult.success(userService.findPage(pageNum, pageSize));
    }

}
